package edu.zut.cs.software.cms.module.student.dao;

import java.util.List;

import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import edu.zut.cs.software.cms.base.dao.GenericDao;
import edu.zut.cs.software.cms.module.all.domain.All;
import edu.zut.cs.software.cms.module.student.domain.Student;

/**
 * student entity's dao interface
 * 
 * @author 任雪燕
 *
 */
@Repository
public interface StudentDao extends GenericDao<Student, Long>{
	
	/**
	 * return an "Student" entity by its "code"
	 * @param code
	 * @return
	 */
	@Query(value="  SELECT * FROM `cms`.`t_student` WHERE `code`=?1 ",nativeQuery=true)
	Student getByStudentCode(@Param("code") String code);	
    

	/**
	 * 通过id返回一个Student对象
	 * @param id
	 * @return
	 */
	@Query(value="  SELECT * FROM `cms`.`t_student` WHERE `id`=?1 ",nativeQuery=true)
	Student selectById(@Param("id") Long id);
	
	
	/**
	 * 返回Student实体的全部数据
	 * @return
	 */
	@Query(value="  SELECT * FROM `cms`.`t_student` ",nativeQuery=true)
	List<Student> selectStudents();
	
	
	/**
	 * 查看id是否存在
	 * @param id
	 * @return
	 */
	@Query(value="  SELECT COUNT(*) FROM `cms`.`t_student` WHERE `code`=?1 ",nativeQuery=true)
	int IfOneExist(@Param("code") String code);

}
